[% setvar title Positional Return Lists Considered Harmful %]
<div id="archive-notice">
    <h3>This file is part of the Perl 6 Archive</h3>
    <p>To see what is currently happening visit <a href="http://www.perl6.org/">http://www.perl6.org/</a></p>
</div>
<div class='pod'>
<a name='TITLE'></a><h1>TITLE</h1>
<p>Positional Return Lists Considered Harmful</p>
<a name='VERSION'></a><h1>VERSION</h1>
<pre>  Maintainer: Jarkko Hietaniemi &lt;<a href='mailto:jhi@iki.fi'>jhi@iki.fi</a>&gt;
  Date: 5 Aug 2000
  Mailing List: <a href='mailto:perl6-language@perl.org'>perl6-language@perl.org</a>
  Number: 37
  Version: 2
  Status: Developing</pre>
<a name='ABSTRACT'></a><h1>ABSTRACT</h1>
<p>Perl has traditionally returned from various functions long (&gt;2) lists
of values.  Some traditions are simply bad.</p>
<a name='DESCRIPTION'></a><h1>DESCRIPTION</h1>
<p>Functions like stat() and get*ent() return long lists of mysterious
values.  The implementation is assumedly easy: just push some values
out of C structs into the Perl return stack.</p>
<p>Wrong.  And once more, wrong.</p>
<p>Firstly, who can remember which one of the stat() return values was
the atime or which is the 4th return value of localtime()?  The
perlfunc gmtime/localtime documentation makes this difficulty painfully
obvious by having to list the indices alongside the values.</p>
<p>Secondly, the current solution is seriously non-extensible.  One
cannot easily add new return values to the APIs because someone may be
expecting an exact number of return values, or someone may be
accessing the values by position from the end of the list Obsoleting
values (or marking them as non-applicable to the current platform) has
to be done by for examples returning undef.</p>
<a name='IMPLEMENTATION'></a><h1>IMPLEMENTATION</h1>
<p>The solution is simple: return hashes instead of lists.  Yes, one
still has to know how the fields are named, so the proposed solution
is still not perfect.</p>
<a name='THE AFFECTED FUNCTIONS'></a><h2>THE AFFECTED FUNCTIONS</h2>
<pre>	caller [1]
	getgrent
	getgrnam
	getgrgid
	gethostbyaddr
	gethostbyname
	gethostent
        getnetbyaddr
	getnetbyname
	getnetent
	getprotobyname
	getprotobynumber
	getprotoent
	getpwent
	getpwnam
	getpwuid
	getservbyname
	getservbyport
	getservent
	gmtime
	localtime
	stat
	</pre>
<p>[1] I guess the whole semantics and functionality of caller() is
severely up for grabs for Perl6.</p>
<p>For the get*() mafia, it is also debatable whether aping the C
interface is a good thing and worth preserving as such at all.  The
preferred interface might be tied hashes.  This interface might also
more naturally support non-POSIX operating systems with their own
native semantics, or POSIX operating systems with extended semantics
like higher security user databases.</p>
<a name='REFERENCES'></a><h1>REFERENCES</h1>
<pre>  perlfunc
  File::stat
  User::grent
  User::pwent</pre>
</div>
